package com.github.bitsapling.sapling;

/**
 * @Data 2025/6/1 17:07
 * @Author cx
 * @Version 1.0
 * @Description GlobalExceptionHandler
 */

import cn.dev33.satoken.exception.NotPermissionException;
import com.github.bitsapling.sapling.result.GraceJSONResult;
import com.github.bitsapling.sapling.result.ResponseStatusEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理 NotPermissionException 异常
     * @param e 权限异常对象
     * @return 包含错误信息的 JSON 结果
     */
    @ExceptionHandler(NotPermissionException.class)
    public GraceJSONResult handleNotPermissionException(NotPermissionException e) {
        return GraceJSONResult.errorCustom(ResponseStatusEnum.NO_PERMISSION_ERROR);
    }
}